package com.plugin.install

import android.content.Context
import android.content.Intent
import android.os.Build
import android.util.Log
import androidx.core.content.FileProvider
import java.io.File
import java.io.FileInputStream
import java.io.FileOutputStream
import java.io.IOException


class Example {
    fun install(context: Context, value: String) {
        val apkFile = File(value);
        Log.i("apkDir", apkFile.path);
        val contentUri =
            FileProvider.getUriForFile(context, context.packageName + ".fileprovider", apkFile);
        Log.i("Dir", context.filesDir.path);
        Log.e("contentUri", contentUri.toString());
        val intent = Intent(Intent.ACTION_VIEW).apply {
            setDataAndType(contentUri, "application/vnd.android.package-archive")
            addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
            addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        }
        context.startActivity(intent)
    }
}
